* Replication code for 'The future of income inequality in the European Union: Do economic growth and poverty matter?' *

// the analysis was performed in Stata/BE 18

// use 'Replication_database.xlsx'


// declare dataset
xtset code year

// descriptive statistics
summarize gdp gini_disp hc_index tert_ed unemp theil top1 pov325 pov55 pov50 ms red infl

// use the already-transformed log variables or compute the natural logarithm of all variables, except hc_index, pov325, pov55, pov50, infl
//e.g.
generate lgdp=ln(gdp)
generate lgini_disp=ln(gini_disp)
generate ltert_ed=ln(tert_ed)
generate lunemp=ln(unemp)
generate ltheil=ln(theil)
generate ltop1=ln(top1)
generate lms=ln(ms)
generate lred=ln(red)

// compute the first-differences of the main variables
generate dgdp=d.lgdp
generate dgini_disp=d.lgini_disp
generate dhcindex=d.hc_index
generate dedu=d.ltert_ed
generate dunemp=d.lunemp
generate dmon=d.lms
generate dred=d.lred

// cross-sectional dependence tests (BP LM, scaled LM, bias-corrected scaled LM, CD) 
* performed in Eviews 12 - command eq_name.cdtest *

// unit root tests (HD test, Pesaran CIPS)

* levels *
xtunitroot hadri lgdp
xtunitroot hadri lgdp, trend
xtunitroot hadri lgini_disp
xtunitroot hadri lgini_disp, trend
xtunitroot hadri hc_index
xtunitroot hadri hc_index, trend
xtunitroot hadri ltert_ed
xtunitroot hadri ltert_ed, trend
xtunitroot hadri lunemp
xtunitroot hadri lunemp, trend

xtcips lgdp, maxlags(1) bglags(1)
xtcips lgdp, maxlags(1) bglags(1) trend
xtcips lgini_disp, maxlags(1) bglags(1)
xtcips lgini_disp, maxlags(1) bglags(1) trend
xtcips hc_index, maxlags(1) bglags(1)
xtcips hc_index, maxlags(1) bglags(1) trend
xtcips ltert_ed, maxlags(1) bglags(1)
xtcips ltert_ed, maxlags(1) bglags(1) trend
xtcips lunemp, maxlags(1) bglags(1)
xtcips lunemp, maxlags(1) bglags(1) trend

* differences *
xtunitroot hadri dgdp
xtunitroot hadri dgini_disp
xtunitroot hadri dhcindex
xtunitroot hadri dedu
xtunitroot hadri dunemp

xtcips dgdp, maxlags(1) bglags(1)
xtcips dgini_disp, maxlags(1) bglags(1)
xtcips dhcindex, maxlags(1) bglags(1)
xtcips dedu, maxlags(1) bglags(1)
xtcips dunemp, maxlags(1) bglags(1)

// Westerlund (2007) cointegration test
xtwest lgdp lgini_disp, lags(1) bootstrap(700)

// Juodis et al. (2021) Granger non-causality test
xtgrangert dgdp dgini, maxlags(4) het nodfc bootstrap
xtgrangert dgdp hc_index, maxlags(4) het nodfc bootstrap
xtgrangert dgdp dgini hc_index, maxlags(4) het nodfc bootstrap
xtgrangert dgini dgdp, maxlags(4) het nodfc bootstrap
xtgrangert dgini hc_index, maxlags(4) het nodfc bootstrap
xtgrangert dgini dgdp hc_index, maxlags(4) het nodfc bootstrap
xtgrangert hc_index dgdp, maxlags(4) het nodfc bootstrap
xtgrangert hc_index dgini, maxlags(4) het nodfc bootstrap
xtgrangert hc_index dgdp dgini, maxlags(4) het nodfc bootstrap

// pvar order selection criteria
pvarsoc dgdp hc_index dgini, maxl(3) pvaropts(instlags(1/3) fod gmmstyle)

// GMM-pvar estimation
pvar dgdp hc_index dgini, lags(1) fod instlags(1/3) gmmstyle vce(hac bartlett opt)

// post-estimation pvar stability checks
pvarstable

// post-estimation granger causality test (optional)
pvargranger

// GMM-pvar estimation with CEE dummy included
pvar dgdp hc_index dgini, lags(1) fod instlags(1/3) gmmstyle vce(hac bartlett opt) exog(Eastd)

// cumulative orthogonalized IRFs for the main variables
pvarirf, oirf cumulative mc(1000) impulse(dgdp dgini hc_index) response(dgini)
porder(dgdp hc_index dgini) step(20)
pvarirf, oirf cumulative mc(1000) impulse(dgdp dgini hc_index) response(dgdp)
porder(dgdp hc_index dgini) step(20)
pvarirf, oirf cumulative mc(1000) impulse(dgdp dgini hc_index) response(hc_index)
porder(dgdp hc_index dgini) step(20)

// FEVD analysis
pvarfevd, porder(dgdp hc_index dgini) mc(1000) step(20)

// Robustness checks

* alternative variables' ordering *

// change variables ordering in the pvar and then estimate pvar and pvarirf with the new ordering
// e.g.
pvar dgdp dgini hc_index, lags(1) fod instlags(1/3) gmmstyle vce(hac bartlett opt)
pvarirf, oirf cumulative mc(1000) impulse(dgdp dgini hc_index) response(dgini)
porder(dgdp dgini hc_index) step(20)

* alternative inequality measures (theil, top1) *

// same unit root checks for ltheil and ltop1 and then first-differencing (dtheil, dtop)

// estimate pvar and pvarirf with dtheil and dtop
pvar dgdp hc_index dtheil, lags(1) fod instlags(1/3) gmmstyle vce(hac bartlett opt)
pvarirf, oirf cumulative mc(1000) impulse(dgdp dtheil hc_index) response(dgini)
porder(dgdp hc_index dtheil) step(20)
pvar dgdp hc_index dtop, lags(1) fod instlags(1/3) gmmstyle vce(hac bartlett opt)
pvarirf, oirf cumulative mc(1000) impulse(dgdp dtop hc_index) response(dgini)
porder(dgdp hc_index dtop) step(20)

* alternative poverty measures (pov325, pov55, pov50) *
pvar dgdp pov325 dgini, lags(1) fod instlags(1/3) gmmstyle vce(hac bartlett opt)
pvarirf, oirf cumulative mc(1000) impulse(dgdp dgini pov325) response(dgini) porder(dgdp pov325 dgini) step(20)
pvar dgdp pov55 dgini, lags(1) fod instlags(1/3) gmmstyle vce(hac bartlett opt)
pvarirf, oirf cumulative mc(1000) impulse(dgdp dgini pov55) response(dgini) porder(dgdp pov55 dgini) step(20)
pvar dgdp pov50 dgini, lags(1) fod instlags(1/3) gmmstyle vce(hac bartlett opt)
pvarirf, oirf cumulative mc(1000) impulse(dgdp dgini pov50) response(dgini) porder(dgdp pov50 dgini) step(20)

* FEVD analysis - additional factors (dedu, dunemp) *
pvar dgdp dedu dunemp hc_index dgini, lags(1) fod instlags(1/3) gmmstyle vce(hac bartlett opt)
pvarfevd, porder(dgdp dedu dunemp hc_index dgini) mc(1000) step(20)

-----------------------------------
* SUBSAMPLE ANALYSIS *
-----------------------------------

* WEST SAMPLE *

// keep from the main dataset only the Western European countries (15 units)
drop if inlist(code, "Bulgaria":code, "Croatia":code, "Czech Republic":code, 
"Hungary":code, "Poland":code, "Romania":code, "Estonia":code, "Latvia":code, 
"Lithuania":code, "Slovenia":code, "Slovakia":code)

// extend the main model with dedu and dunemp as endogeneous factors

// same model identification and estimations steps as for the entire dataset

// GMM-pvar estimation
pvar dgdp dedu dunemp hc_index dgini, lags(1) fod instlags(1/4) gmmstyle vce(hac bartlett opt)

// cumulative orthogonalized IRFs - ineq. response
pvarirf, oirf cumulative mc(1000) impulse(dedu) response(dgini) porder(dgdp dedu dunemp hc_index dgini) step(20)
pvarirf, oirf cumulative mc(1000) impulse(dunemp) response(dgini) porder(dgdp dedu dunemp hc_index dgini) step(20)
pvarirf, oirf cumulative mc(1000) impulse(dgdp) response(dgini) porder(dgdp dedu dunemp hc_index dgini) step(20)

* EAST SAMPLE *

// keep from the main dataset only the Eastern European countries (11 units)
 drop if inlist(code, "Austria":code, "Belgium":code, "Denmark":code, 
"Finland":code, "France":code, "Germany":code, "Greece":code, "Ireland":code, 
"Italy":code, "Luxembourg":code, "Netherlands":code, "Portugal":code, "Spain":code, "Sweden":code, "United Kingdom":code)

// extend the main model with dedu and dunemp as endogeneous factors

// same model identification and estimations steps as for the Western sample

// GMM-pvar estimation
pvar dgdp dedu dunemp hc_index dgini, lags(1) fod instlags(1/3) gmmstyle vce(hac bartlett opt)

// cumulative orthogonalized IRFs - ineq. response
pvarirf, oirf cumulative mc(1000) impulse(dedu) response(dgini) porder(dgdp dedu dunemp hc_index dgini) step(20)
pvarirf, oirf cumulative mc(1000) impulse(dunemp) response(dgini) porder(dgdp dedu dunemp hc_index dgini) step(20)
pvarirf, oirf cumulative mc(1000) impulse(dgdp) response(dgini) porder(dgdp dedu dunemp hc_index dgini) step(20)

* EUROZONE SAMPLE *

// keep from the main dataset only the Eurozone countries (17 units)
drop if inlist(code, "Bulgaria":code, "Croatia":code, "Czech Republic":code, "Denmark":code, "Hungary":code, "Poland":code, "Romania":code, "Sweden":code, "United Kingdom":code)

// extend the main model with dmon, dred and infl as endogeneous factors

// same model identification and estimations steps as for the other subsamples

// GMM-pvar estimation
pvar dgdp infl dmon dred hc_index dgini, lags(1) fod instlags(1/4) gmmstyle vce(hac bartlett opt)

// cumulative orthogonalized IRFs - ineq. response
pvarirf, oirf cumulative mc(1000) impulse(dred) response(dgini) porder(dgdp infl dmon dred hc_index dgini) step(20)
pvarirf, oirf cumulative mc(1000) impulse(dmon) response(dgini) porder(dgdp infl dmon dred hc_index dgini) step(20)
pvarirf, oirf cumulative mc(1000) impulse(dgdp) response(dgini) porder(dgdp infl dmon dred hc_index dgini) step(20)

* NON-EUROZONE SAMPLE *

// keep from the main dataset only the Non-Eurozone countries (9 units)
 drop if inlist(code, "Austria":code, "Belgium":code, "Estonia":code, 
"Finland":code, "France":code, "Germany":code, "Greece":code, "Ireland":code, 
"Italy":code, "Latvia":code, "Lithuania":code,"Luxembourg":code, "Netherlands":code, "Portugal":code, "Spain":code, "Slovakia":code, "Slovenia":code)

// extend the main model with dmon, dred and infl as endogeneous factors

// same model identification and estimations steps as for the other subsamples

// GMM-pvar estimation
pvar dgdp infl dmon dred hc_index dgini, lags(1) fod instlags(1/4) gmmstyle vce(hac bartlett opt)

// cumulative orthogonalized IRFs - ineq. response
pvarirf, oirf cumulative mc(1000) impulse(dred) response(dgini) porder(dgdp infl dmon dred hc_index dgini) step(20)
pvarirf, oirf cumulative mc(1000) impulse(dmon) response(dgini) porder(dgdp infl dmon dred hc_index dgini) step(20)
pvarirf, oirf cumulative mc(1000) impulse(dgdp) response(dgini) porder(dgdp infl dmon dred hc_index dgini) step(20)
